package edu.rpi.bt.client;

import com.apress.progwt.client.college.ServiceCache;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;

import edu.rpi.bt.client.domain.Destination;


/**
 * 
 * @author Nate
 *
 * A smaller panel to show onMouseOver
 */
public class LocationPanelSmall extends LocationPanel {
//    private ServiceCache serviceCache;

    private Panel contentPanel = new Panel();
    
    LocationPanelSmall( ServiceCache servCache, Destination dest ){
        this.serviceCache = servCache;
        destination = dest;
        makeServiceCalls();
        buildPanel();
    }
/*
    LocationPanelSmall( ServiceCache servCache, long locId ){
        this.serviceCache = servCache;
        loadData(locId);
        buildPanel();
    }
  */  
    @Override
    void loadData( long locId ) {
        
        
    }
    
    void buildPanel(){
        setWidth(250);
        setHeight(200);
        setPaddings(0);
      
        String[] photoUrls = getImageUrls(0);
        
/*        
        add(new Panel(){{
            setWidth(250);
            setHeight(150);
            setHtml(panelHtml);
            setBorder(false);
        }});
  */      
        contentPanel.setWidth(250);
        contentPanel.setHeight(150);
        contentPanel.setBorder(false);
        add(contentPanel);

        
        add(new Button("See more..."){{
            addListener(new ButtonListenerAdapter() {  
                public void onClick(Button button, EventObject e) {  
                    LocationPanelFull lpf = new LocationPanelFull( serviceCache, destination ); 
                    Window w = new Window();
                    w.add(lpf);
                    w.setWidth(800);
                    w.setHeight(600);
                    w.setPlain(true);  
                    w.setModal(true);
                    w.setTitle( destination.getName() );
                    w.setClosable(true);
                    w.setDraggable(true);
                    w.show();
                }  
            });
        }});
    }

    private String trimIt( String text, int length ){
        return text;
    }

    protected void setupImages(){
        //MessageBox.alert("Images ready!");
        String panelHtml = "<table cellpadding=\"3\" class=\"btSmallContent\"><tr><td colspan=\"2\" class=\"locname\">" + destination.getName() + "</td></tr>" +
        "<tr><td class=\"locdescrip\">" + trimIt( destination.getDescription(), 70 ) +
//        "<span> - " + destination.getUser().getUsername() + "</span>" +
        "</td>" +
        "<td>" +  getImageTags( 1 ) + "</td></tr>" +
//      "<tr><td colspan=\"2\">\"I liked this place too - had a great time doing this and that and the other. You should try going during June when the...\" - </i>Joe Traveler</i></td></tr>" +
        "</table>";
        
        contentPanel.setHtml(panelHtml);
     
    }
    
}
